/**
 * 16进制颜色转换 rgba颜色数组
 * 转化后颜色饱和度阈值 0 - 1 
 * @param {string} value 16进制颜色  默认 #FFFFFF  可携带透明度
 * @param {Number} opacity 透明度 0 - 1
 * 
 * @returns {Array} rgba颜色数组
 */
function ColorArray (value, opacity) {
    // #ffffff
    if (!value) value = '#ffffff';
    let hex = value[0] == '#' ? value.replace('#', '') : value;
    let r = 0, g = 0, b = 0, a = opacity === undefined ? 1 : opacity;
    if (hex.length == 6) {
        r = Number((parseInt('0x' + hex.slice(0,2)) / 255).toFixed(2))
        g = Number((parseInt('0x' + hex.slice(2,4)) / 255).toFixed(2))
        b = Number((parseInt('0x' + hex.slice(4,8)) / 255).toFixed(2))
    };
    if (hex.length == 8 && opacity === undefined) {
        a = Number((parseInt('0x' + hex.slice(4,8)) / 255).toFixed(2))
    };
    return [ r, g, b, a ];
}

export default ColorArray